/**************************************************************************
** Yabet is bloging editor tool that supports many blog's formats. It is very usefull for crossposting, allows easily to
** make posts to your blogs.
**
** Copyright (C) 2010 Valery Konchin <eeexception@gmail.com>
**
** This program is free software: you can redistribute it and/or modify
**     it under the terms of the GNU General Public License as published by
**     the Free Software Foundation, either version 3 of the License, or
**     (at your option) any later version.
**
**     This program is distributed in the hope that it will be useful,
**     but WITHOUT ANY WARRANTY; without even the implied warranty of
**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
**     GNU General Public License for more details.
**
**     You should have received a copy of the GNU General Public License
**     along with this program.  If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/

#include "customyabettextmarkup.h"
#include <QSettings>

const YabetLogHandler* CustomYabetTextMarkup::log = new YabetLogHandler("CustomYabetTextMarkup");

CustomYabetTextMarkup::CustomYabetTextMarkup(QString file)
{
    QSettings settings(file, QSettings::IniFormat);

    this->markupName = settings.value("name", "undefined").toString();

    this->postSite = settings.value("post-site", "about:home").toString();
    this->postUrl = settings.value("post-url", "about:home").toString();

    this->configVersion = settings.value("version", YabetTextMarkup::PROPERTIES_FILE_VERSION).toString();

    this->markupElements.insert(YabetTextMarkup::BOLD_ELEMENT_NAME,
                                new YabetTextMarkupElement(settings.value(YabetTextMarkup::BOLD_ELEMENT_NAME, "").toString()));
    this->markupElements.insert(YabetTextMarkup::ITALIC_ELEMENT_NAME,
                                new YabetTextMarkupElement(settings.value(YabetTextMarkup::ITALIC_ELEMENT_NAME, "").toString()));
    this->markupElements.insert(YabetTextMarkup::CODE_ELEMENT_NAME,
                                new YabetTextMarkupElement(settings.value(YabetTextMarkup::CODE_ELEMENT_NAME, "").toString()));
    this->markupElements.insert(YabetTextMarkup::LINK_ELEMENT_NAME,
                                new YabetTextMarkupElement(settings.value(YabetTextMarkup::LINK_ELEMENT_NAME, "").toString()));
    this->markupElements.insert(YabetTextMarkup::IMAGE_ELEMENT_NAME,
                                new YabetTextMarkupElement(settings.value(YabetTextMarkup::IMAGE_ELEMENT_NAME, "").toString()));
    this->markupElements.insert(YabetTextMarkup::TEXT_CUT_ELEMENT_NAME,
                                new YabetTextMarkupElement(settings.value(YabetTextMarkup::TEXT_CUT_ELEMENT_NAME, "").toString()));
    this->markupElements.insert(YabetTextMarkup::VIDEO_ELEMENT_NAME,
                                new YabetTextMarkupElement(settings.value(YabetTextMarkup::VIDEO_ELEMENT_NAME, "").toString()));
    this->markupElements.insert(YabetTextMarkup::LINE_BREAK_ELEMENT_NAME,
                                new YabetTextMarkupElement(settings.value(YabetTextMarkup::LINE_BREAK_ELEMENT_NAME, "").toString()));
    this->markupElements.insert(YabetTextMarkup::LIST_ELEMENT_NAME,
                                new YabetTextMarkupElement(settings.value(YabetTextMarkup::LIST_ELEMENT_NAME, "").toString()));
    this->markupElements.insert(YabetTextMarkup::USER_ELEMENT_NAME,
                                new YabetTextMarkupElement(settings.value(YabetTextMarkup::USER_ELEMENT_NAME, "").toString()));
    this->markupElements.insert(YabetTextMarkup::QUOTE_ELEMENT_NAME,
                                new YabetTextMarkupElement(settings.value(YabetTextMarkup::QUOTE_ELEMENT_NAME, "").toString()));
    this->markupElements.insert(YabetTextMarkup::PARAGRAPH_ELEMENT_NAME,
                                new YabetTextMarkupElement(settings.value(YabetTextMarkup::PARAGRAPH_ELEMENT_NAME, "").toString()));

    log->debugMsg("Markup element image: " + markupElements.value(YabetTextMarkup::IMAGE_ELEMENT_NAME)->getMarkupName());
    log->debugMsg("Markup element link: " + markupElements.value(YabetTextMarkup::LINK_ELEMENT_NAME)->getMarkupName());
}

QString CustomYabetTextMarkup::getConfigVersion() {
    return configVersion;
}

QString CustomYabetTextMarkup::getMarkupName() {
    return markupName;
}

YabetTextMarkupElement* CustomYabetTextMarkup::getMarkupElement(QString markupElementName) {
    return markupElements.value(markupElementName, new YabetTextMarkupElement(""));
}

QStringList CustomYabetTextMarkup::getMarkupElementsNames() {
    return QStringList(markupElements.keys());
}

QString CustomYabetTextMarkup::getPostSite() {
    return postSite;
}

QString CustomYabetTextMarkup::getPostUrl() {
    return postUrl;
}
